home *** CD-ROM | disk | FTP | other *** search
- /*
- File: U3DDrawing.h
-
- Contains: Headers for 3D drawing routines.
-
- Written by: Jamie Osborne, Robin Mair, Faulkner White, Henri Lamiraux
-
- Copyright: © 1992-1993 by Apple Computer, Inc.
-
- */
-
- #ifndef __U3DDRAWING__
- #define __U3DDRAWING__
-
- #ifndef __UCONTROL__
- #include <UControl.h>
- #endif
-
- #ifndef __ICONS__
- #include "Icons.h"
- #endif
-
- // 8Bit gray shade constants
- const short kRGB8BitGray1 = 61166; // Light gray
- const short kRGB8BitGray2 = 56797; // Slightly darker gray
- const short kRGB8BitGray3 = 52428; // Slightly darker gray
- const short kRGB8BitGray4 = 48059; // Slightly darker gray
- const short kRGB8BitGray5 = 43690; // Slightly darker gray
- const short kRGB8BitGray6 = 34952; // Slightly darker gray
- const short kRGB8BitGray7 = 30583; // Slightly darker gray
- const short kRGB8BitGray8 = 21845; // Slightly darker gray
- const short kRGB8BitGray9 = 17476; // Slightly darker gray
- const short kRGB8BitGray10 = 8738; // Slightly darker gray
- const short kRGB8BitGray11 = 4369; // Dark gray
-
- // 4Bit gray shade constants
- const short kRGB4BitGray1 = 49152; // Light gray
- const short kRGB4BitGray2 = 32768; // Medium gray
- const short kRGB4BitGray3 = 8192; // Dark gray
-
- // Some constants for drawing grays
- const CRGBColor kLightGray = CRGBColor(kRGB8BitGray1, kRGB8BitGray1, kRGB8BitGray1);
- const CRGBColor kLightGray2 = CRGBColor(kRGB8BitGray2, kRGB8BitGray2, kRGB8BitGray2);
- const CRGBColor kLightGray4 = CRGBColor(kRGB8BitGray4, kRGB8BitGray4, kRGB8BitGray4);
- const CRGBColor kMediumLightGray = CRGBColor(kRGB8BitGray5, kRGB8BitGray5, kRGB8BitGray5);
- const CRGBColor kMediumGray = CRGBColor(kRGB8BitGray6, kRGB8BitGray6, kRGB8BitGray6);
-
- //======================================================================================
- // InitU3DDrawing
- // This function initializes the 3D library. You must call this function in your
- // initialization routine.
- //======================================================================================
-
- pascal void InitU3DDrawing();
-
-
- //====================================================================================
- // •••••••••••••••••••••••••••• 3D Utility Classes •••••••••••••••••••••••••••••••••••
- //====================================================================================
-
- //======================================================================================
- // CGRAPHICSSTATE
- // A stack-based object that remembers the graphics state (BW and color)
- // and restores it when it passes out of scope
- //======================================================================================
-
- class CGraphicsState
- {
- private:
- CRGBColor fSaveForeColor;
- CRGBColor fSaveBackColor;
- PenState fSavePenState;
- TextStyle fSaveTextStyle;
-
- public:
- CGraphicsState(); // Constructor is called automatically
- ~CGraphicsState(); // Destructor called automatically
-
- void Save();
- void Restore();
-
- }; // CGraphicsState
-
-
- //======================================================================================
- // CDRAWPERDEVICE
- // A stack-based object that allows drawing in different pixel depths across
- // different monitors
- // If you're not using C++, just use DeviceLoop. It's faster than CDrawPerDevice
- // However, if you are using C++, CDrawPerDevice can save you some headaches
- // having to deal with static drawing routines and the like
- //======================================================================================
-
- class CDrawPerDevice
- {
- private:
- CRect fGlobalArea;
- GDHandle fGDHandle;
- RgnHandle fSaveClip;
- FocusRec fFocus;
- Boolean fDoneOldQD;
-
- public:
- CDrawPerDevice();
- CDrawPerDevice(const CRect& area);
- ~CDrawPerDevice();
-
- pascal void SetDrawingArea(const CRect& area);
- pascal Boolean NextDevice(short& pixelSize);
-
- }; // CDrawPerDevice
-
-
- //======================================================================================
- // CPenNormal
- // Sets the fore and back color to black and white and calls PenNormal
- //======================================================================================
-
- pascal void CPenNormal();
-
-
- //====================================================================================
- // •••••••••••••••••••••••••••• 3D TView Adorners •••••••••••••••••••••••••••••••••••
- //====================================================================================
-
- const IDType kGrayBackgroundAdorner = 'grba';
- const IDType kWhiteBackgroundAdorner = 'whba';
- const IDType k3DGrayBackgroundAdorner = '3dgb';
- const IDType k3DLineTopAdorner = '3dlt';
- const IDType k3DLineBottomAdorner = '3dlb';
- const IDType k3DLineLeftAdorner = '3dll';
- const IDType k3DLineRightAdorner = '3dlr';
- const IDType k3DFrameAdorner = '3dfr';
-
-
- class TWhiteBackgroundAdorner : public TAdorner
- {
- public:
- virtual pascal void Initialize();
- virtual pascal void IWhiteBackgroundAdorner(Boolean freeOnDeletion);
- virtual pascal void Draw(TView* itsView, const VRect& area);
- };
-
- class TGrayBackgroundAdorner : public TAdorner
- {
- public:
- virtual pascal void Initialize();
- virtual pascal void IGrayBackgroundAdorner(Boolean freeOnDeletion);
- virtual pascal void Draw(TView* itsView, const VRect& area);
- };
-
-
- class T3DGrayBackgroundAdorner : public TGrayBackgroundAdorner
- {
- public:
- virtual pascal void Initialize();
- virtual pascal void I3DGrayBackgroundAdorner(Boolean freeOnDeletion);
- virtual pascal void Draw(TView* itsView, const VRect& area);
- };
-
-
- class T3DLineTopAdorner : public TAdorner
- {
- public:
- virtual pascal void Initialize();
- virtual pascal void I3DLineTopAdorner(Boolean freeOnDeletion);
- virtual pascal void Draw(TView* itsView, const VRect& area);
- };
-
-
- class T3DLineBottomAdorner : public TAdorner
- {
- public:
- virtual pascal void Initialize();
- virtual pascal void I3DLineBottomAdorner(Boolean freeOnDeletion);
- virtual pascal void Draw(TView* itsView, const VRect& area);
- };
-
- class T3DLineLeftAdorner : public TAdorner
- {
- public:
- virtual pascal void Initialize();
- virtual pascal void I3DLineLeftAdorner(Boolean freeOnDeletion);
- virtual pascal void Draw(TView* itsView, const VRect& area);
- };
-
- class T3DLineRightAdorner : public TAdorner
- {
- public:
- virtual pascal void Initialize();
- virtual pascal void I3DLineRightAdorner(Boolean freeOnDeletion);
- virtual pascal void Draw(TView* itsView, const VRect& area);
- };
-
-
- class T3DFrameAdorner : public TAdorner
- {
- public:
- virtual pascal void Initialize();
- virtual pascal void I3DFrameAdorner(Boolean freeOnDeletion);
- virtual pascal void Draw(TView* itsView, const VRect& area);
- };
-
-
- //====================================================================================
- // ••••••••••••••••• TControl classes and auxiliary adorners •••••••••••••••••••••••
- //====================================================================================
-
- //====================================================================================
- // T3DCheckBox
- // A 3D version of the check box control. This class circumvents the control CDEF
- //====================================================================================
-
- class T3DCheckBox : public TCheckBox
- {
- protected:
- VRect fDrawBox;
- CRGBColor fForeColor, fBackColor;
-
- public:
- virtual pascal void Initialize();
- virtual pascal void DoPostCreate(TDocument *itsDocument);
- virtual pascal void I3DCheckBox (TView* itsSuperView, const VPoint& itsLocation,
- const VPoint& itsSize, SizeDeterminer itsHSizeDet,
- SizeDeterminer itsVSizeDet, const CStr255& itsLabel,
- Boolean isTurnedOn);
- virtual pascal TObject* Clone();
- virtual pascal void Free();
-
- virtual pascal void DoMouseCommand(VPoint& theMouse,TToolboxEvent*,CPoint);
- virtual pascal void TrackMouse(TrackPhase aTrackPhase, VPoint& anchorPoint, VPoint& previousPoint,
- VPoint& nextPoint, Boolean);
-
- virtual pascal void Draw(const VRect& area);
- virtual pascal void DimState(Boolean state,Boolean redraw);
- virtual pascal void SetLongVal(VCoordinate itsVal, Boolean redraw);
- virtual pascal void HiliteState(Boolean state,Boolean redraw);
- virtual pascal void Hilite();
- virtual pascal void Dim();
- inline pascal void SetBackColor(CRGBColor newColor) {fBackColor = newColor;}
- virtual pascal void InstallColor(const CRGBColor& theColor, Boolean redraw);
-
- private:
- virtual pascal void DrawBoxText(const CStr255& s, const CRect& box, Boolean preferOutline);
- virtual pascal void DrawBox();
- virtual pascal void DrawCheck();
-
- }; // T3DCheckBox
-
-
- //====================================================================================
- // T3DRadio
- // A 3D version of the radio button. This class circumvents the control CDEF
- //====================================================================================
-
- class T3DRadio : public TRadio
- {
- protected:
- VRect fDrawBox;
- CRGBColor fForeColor, fBackColor;
-
- public:
- virtual pascal void Initialize();
- virtual pascal void DoPostCreate(TDocument *itsDocument);
- virtual pascal void I3DRadio (TView* itsSuperView, const VPoint& itsLocation,
- const VPoint& itsSize, SizeDeterminer itsHSizeDet,
- SizeDeterminer itsVSizeDet, const CStr255& itsLabel,
- Boolean isTurnedOn);
- virtual pascal TObject* Clone();
- virtual pascal void Free();
-
- virtual pascal void DoMouseCommand(VPoint& theMouse,TToolboxEvent*,CPoint);
- virtual pascal void TrackMouse(TrackPhase aTrackPhase, VPoint& anchorPoint, VPoint& previousPoint,
- VPoint& nextPoint, Boolean);
-
- virtual pascal void Draw(const VRect& area);
- virtual pascal void DimState(Boolean state,Boolean redraw);
- virtual pascal void SetLongVal(VCoordinate itsVal, Boolean redraw);
- virtual pascal void HiliteState(Boolean state,Boolean redraw);
- virtual pascal void Hilite();
- virtual pascal void Dim();
- inline pascal void SetBackColor(CRGBColor newColor) {fBackColor = newColor;}
- virtual pascal void InstallColor(const CRGBColor& theColor, Boolean redraw);
-
- private:
- virtual pascal void DrawBoxText(const CStr255& s, const CRect& box, Boolean preferOutline);
- virtual pascal void DrawBox();
- virtual pascal void DrawCheck();
- };
-
-
- //====================================================================================
- // T3DButton
- // A 3D version of the push button. This class circumvents the control CDEF
- //====================================================================================
-
- class T3DButton : public TButton
- {
- protected:
- TAdorner* f3DAdorner;
- CRGBColor fHilitedTextColor;
-
- public:
- virtual pascal void Initialize();
- virtual pascal void DoPostCreate(TDocument *itsDocument);
- virtual pascal void I3DButton(TView* itsSuperView, const VPoint& itsLocation,
- const VPoint& itsSize, SizeDeterminer itsHSizeDet,
- SizeDeterminer itsVSizeDet, const CStr255& itsLabel);
- virtual pascal TObject* Clone();
- virtual pascal void Free();
- virtual pascal void CreateButtonAdorner();
-
- virtual pascal void DoMouseCommand(VPoint& theMouse,TToolboxEvent*,CPoint);
- virtual pascal void TrackMouse(TrackPhase aTrackPhase, VPoint& anchorPoint, VPoint& previousPoint,
- VPoint& nextPoint, Boolean);
-
- virtual pascal void DimState(Boolean state,Boolean redraw);
- virtual pascal void HiliteState(Boolean state,Boolean redraw);
- virtual pascal void Draw(const VRect& area);
- virtual pascal void Hilite();
- virtual pascal void Dim();
- inline pascal void SetHilitedTextColor(const CRGBColor& color) { fHilitedTextColor = color; }
-
- private:
- virtual pascal void DrawBoxText(const CStr255& s, const CRect& box, Boolean preferOutline );
-
- }; // T3DButton
-
-
- //====================================================================================
- // T3DTextButtonAdorner
- // Adorner used by the T3DButton class for 3D drawing.
- //====================================================================================
-
- // Round Rect Oval Constants
- const short kOvalWidth = 10;
- const short kOvalHeight = 10;
-
- const IDType k3DTextButtonAdorner= '3dtb';
-
- class T3DTextButtonAdorner : public TAdorner
- {
- public:
- virtual pascal void I3DTextButtonAdorner(Boolean freeOnDeletion);
- virtual pascal void Draw(TView* itsView, const VRect& area);
-
- private:
- virtual pascal void Draw8Bit(const CRect& rect, Boolean hilite );
- virtual pascal void Draw4Bit(const CRect& rect, Boolean hilite );
- virtual pascal void Draw1Bit(const CRect& rect, Boolean hilite );
- virtual pascal void Frame(const CRect& rect);
- virtual pascal void TopLeftCorner(const CRect& rect, const CRGBColor light,
- const CRGBColor dark, Boolean hilite );
- virtual pascal void BotLeftCorner(const CRect& rect, const CRGBColor light,
- const CRGBColor dark, Boolean hilite );
- virtual pascal void TopRightCorner(const CRect& rect, const CRGBColor light,
- const CRGBColor dark, Boolean hilite );
- virtual pascal void BotRightCorner(const CRect& rect, const CRGBColor light,
- const CRGBColor dark, Boolean hilite );
-
- }; // T3DTextButtonAdorner
-
-
- //====================================================================================
- // ••••••••••••••••• 3DIconButton class and auxiliary adorner •••••••••••••••••••••••
- //====================================================================================
-
- //====================================================================================
- // TYPES
- //====================================================================================
-
- typedef short ButtonMode; // Used to store the mode for Icon Buttons
-
- //====================================================================================
- // CONSTANTS
- //====================================================================================
-
- const IDType k3DIconAdorner = '3dia'; // IDType for our adorner
- const Boolean kButtonOn = TRUE; // State button on
- const Boolean kButtonOff = FALSE; // State button off
- const ButtonMode kButtonMode = 1; // Normal button Mode for state buttons
- const ButtonMode kSwitchMode = 2; // Toggle Mode for state buttons - default
- const ButtonMode kRadioMode = 3; // Exclusivity Mode for state buttons
-
- //====================================================================================
- // T3DIconAdorner
- // Adorner used by the T3DIconButton class for 3D drawing.
- //====================================================================================
-
- class T3DIconAdorner : public TAdorner
- {
- public:
- virtual pascal void I3DIconAdorner(Boolean freeOnDeletion);
- virtual pascal void Draw(TView* itsView, const VRect& area);
-
- private:
- virtual pascal void Draw8Bit(const CRect& rect, Boolean hilite);
- virtual pascal void Draw4Bit(const CRect& rect, Boolean hilite);
- virtual pascal void Draw1Bit(const CRect& rect, Boolean hilite);
- virtual pascal void Frame(const CRect& rect);
- virtual pascal void TopLeftSide(const CRect& rect);
- virtual pascal void BotRightSide(const CRect& rect);
- virtual pascal void TopLeftCorner(const CRect& rect, const CRGBColor light,
- const CRGBColor dark );
- virtual pascal void BotLeftCorner(const CRect& rect, const CRGBColor light,
- const CRGBColor dark );
- virtual pascal void TopRightCorner(const CRect& rect, const CRGBColor light,
- const CRGBColor dark );
- virtual pascal void BotRightCorner(const CRect& rect, const CRGBColor light,
- const CRGBColor dark, Boolean hilite );
-
- }; // T3DIconAdorner
-
-
- //====================================================================================
- // TIconSuite
- // Base class for the T3DIconButton. This class draws icon suites (icl#).
- //====================================================================================
-
- const EventNumber mIconSuiteHit = 1100; // Hit in an Icon Suite
-
- class TIconSuite: public TControl
- {
- private:
-
- ResNumber fIconSuiteRsrcID; // Resource ID for the family of icons
- IconAlignmentType fAlignment; // Type of alignment we would like
- Handle fDataHandle; // Data handle for the icon family
- IconSelectorValue fSelectorValue;
-
- public:
- virtual pascal void Initialize ();
- virtual pascal void IIconSuite (TView* itsSuperView, const VPoint& itsLocation,
- const VPoint& itsSize, SizeDeterminer itsHSizeDet,
- SizeDeterminer itsVSizeDet, ResNumber itsRsrcID,
- IconAlignmentType alignment, IconSelectorValue selectorValue);
- virtual pascal void DoPostCreate(TDocument *itsDocument);
-
- virtual pascal TObject* Clone();
- virtual pascal void Free();
- virtual pascal void ReleaseIconSuite();
-
- virtual pascal void GetIconRect(VRect& theRect);
- virtual pascal void SetIconSuiteRsrcID(short itsRsrcID, IconSelectorValue selectorValue,
- Boolean redraw );
- virtual pascal void SetIconSuite(Handle theSuite, Boolean redraw );
- virtual pascal void SetAlignment(IconAlignmentType newAlignment, Boolean redraw );
-
- virtual pascal void Draw(const VRect& area);
- virtual pascal void Dim();
- virtual pascal void Hilite();
-
- private:
- virtual pascal void DoPlotIconSuite(IconTransformType transform);
-
- }; // TIconSuite
-
-
- //====================================================================================
- // T3DIconButton
- // Implementation of 3d Icon button in color where available.
- //====================================================================================
- const EventNumber mIconButtonHit = 1102; // Hit in an Icon Suite
-
-
- class T3DIconButton : public TIconSuite
- {
- protected:
- TAdorner* f3DIconAdorner; // Reference to the adorner that does
- ButtonMode fMode; // What mode is this button operating under the initial
- // possibilities are : kRadioMode
- // kSwitchMode
- // kButtonMode
- Boolean fState; // Used to maintain the state of the button during tracking
-
- private:
- short fIconSize; // Either 12, 16 or 32
-
- public:
-
- T3DIconButton() {};
- virtual pascal void Initialize();
- virtual pascal void I3DIconButton(TView* itsSuperView, const VPoint& itsLocation,
- const VPoint& itsSize, SizeDeterminer itsHSizeDet,
- SizeDeterminer itsVSizeDet, short iconSize,
- ResNumber itsRsrcID, ButtonMode mode,
- Boolean state );
- virtual pascal void DoPostCreate(TDocument *itsDocument);
- virtual pascal void CreateButtonAdorner ();
-
- virtual pascal void GetIconRect(VRect& theRect);
- virtual pascal void SetIconRsrcID(short itsRsrcID, Boolean redraw );
- virtual pascal void SetMode(ButtonMode newMode);
- virtual pascal ButtonMode GetMode();
- virtual pascal Boolean IsSelected();
- virtual pascal void TrackMouse(TrackPhase aTrackPhase,VPoint& ,
- VPoint& , VPoint& nextPoint,Boolean );
- virtual pascal void Hilite();
- virtual pascal void Dim();
-
- private:
- virtual pascal short GetIconSize(const VPoint& viewSize);
- virtual pascal void SetIconSuiteRsrcID(short itsRsrcID, IconSelectorValue selectorValue,
- Boolean redraw );
- virtual pascal void SetIconSuite(Handle theSuite, Boolean redraw);
-
- }; // T3DIconButton
-
-
- #endif __U3DDRAWING__